{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 原文地址 [www.cnblogs.com](https://www.cnblogs.com/zhangshuyx/p/5383582.html)\n",
    "\n",
    "由于工作中需要做一些服务器维护，为方便维护，在服务器上安装了一个 4G 无线上网卡。但是由于网络不稳定，经常在使用一两天后就断开，无法远程连接，甚是苦恼。在网上找了挺久也没有发现什么好的解决办法。\n",
    "\n",
    "正好今天网络搜索发现了一个帖子《[待机唤醒后自动连接宽带](http://www.cnblogs.com/eineseite/archive/2009/06/16/1504247.html)》，和我要解决的问题有异曲同工的感觉，于是便试了一试，果然好用，赶紧分享给大家。\n",
    "\n",
    "**1、首先新建文本文件，写入以下 vbs 代码，并保存为 vbs 文件；**\n",
    "\n",
    "```\n",
    "createobject(\"wscript.shell\").run\"rasdial 宽带连接名称 用户名 密码\",0\n",
    "\n",
    "```\n",
    "\n",
    "这行代码可以实现指定宽带连接的拨号。我这里的无线上网卡，没有用户名密码，直接填上宽带名称就行，保存为 cmiot.vbs。\n",
    "\n",
    "```\n",
    "createobject(\"wscript.shell\").run\"rasdial cmiot\",0\n",
    "\n",
    "```\n",
    "\n",
    "**2、新建任务计划，在网络断开时自动重拨；**\n",
    "\n",
    "受这篇文章《[使用 Python 控制 DDNS 解析](https://www.forzw.com/archives/745)》的启发，观察了一下上网卡连接断开时的系统事件。\n",
    "\n",
    "[![](https://images2015.cnblogs.com/blog/487962/201604/487962-20160412174049895-445662515.png)](http://images2015.cnblogs.com/blog/487962/201604/487962-20160412174043738-1199131914.png)\n",
    "\n",
    "可以看到，在每次网络连接和断开时 Isatap 接口都会产生新事件，事件 ID 分别为 4200 和 4201，这样就好办了，我们只需要在 Isatap 接口产生 4201 事件时运行 cmiot.vbs 程序就可以实现断线重拨。\n",
    "\n",
    "新建任务计划程序，触发器选择 “当特定事件被记录时”，触发器内容如下填写，操作选择 “启动程序”，并选定第一步保存的 vbs 文件，完成即可。\n",
    "\n",
    "[![](https://images2015.cnblogs.com/blog/487962/201604/487962-20160412174055254-640580522.png)](http://images2015.cnblogs.com/blog/487962/201604/487962-20160412174051910-1194806338.png)\n",
    "\n",
    "**3、实测效果**\n",
    "\n",
    "断开网络进行测试，果然在 4201 事件出现后不久，上报 4200 事件，并且网络自动连接成功。\n",
    "\n",
    "[![](https://images2015.cnblogs.com/blog/487962/201604/487962-20160412174101566-1170001798.png)](http://images2015.cnblogs.com/blog/487962/201604/487962-20160412174100238-687223802.png)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
